package com.blb.exam.student.dao.impl;

import com.blb.common.entity.User;
import com.blb.common.utils.DBUtils;
import com.blb.exam.student.dao.UserDAO;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UserDAOImpl implements UserDAO {

    @Override
    public User selectByNameAndPassword(String username, String password) {
        List<User> users = DBUtils.executeQuery(User.class, "select * from t_user where username=? and password=?", username, password);
        if(users != null && !users.isEmpty()){
            return users.get(0);
        }
        return null;
    }

    @Override
    public int insert(User user) {
        return DBUtils.executeUpdate("insert into t_user(username,password,nickname,cellphone,type) values(?,?,?,?,?)",
                user.getUsername(),user.getPassword(),user.getNickname(),user.getCellphone(),user.getType());
    }

    @Override
    public List<User> selectByName(String username) {
        return DBUtils.executeQuery(User.class,"select *  from t_user where username = ?",username);
    }
}
